package com.niit.utils

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerConfig, ProducerRecord}

import java.util

object kafkaUtil {

  def writer(key:String,res_str:String):Unit = {
      val kafkaProp = new util.HashMap[String, Object]()
      //本地调试的时候是niit01，线上是149.104.24.160
      kafkaProp.put("bootstrap.servers", "192.168.244.129:9092")
      kafkaProp.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer")
      kafkaProp.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer")
      val producer = new KafkaProducer[String, String](kafkaProp)
      producer.send(new ProducerRecord[String, String]("result",key,res_str))
      producer.close()
    }
}
